package com.book.controller.page;

import com.book.entity.Users;
import com.book.service.BookService;
import com.book.service.StatisticsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;

/**
 * @Author zzw2000
 * @Date 2022年08月26日 19:59
 * @Description 描述
 */
@Controller
@RequestMapping("/page/admin")
public class AdminPageController {

    @Resource
    private BookService bookService;
    @Resource
    private StatisticsService statisticsService;

    @GetMapping("/index")
    public String index(@SessionAttribute(value = "user", required = false) Users users, Model model) {
        model.addAttribute("user", users);
        model.addAttribute("borrowInfo", bookService.borrowInfo(users));
        model.addAttribute("statistics", statisticsService.getStatistics());
        return "/admin/index";
    }

    @GetMapping("/book")
    public String book(@SessionAttribute(value = "user", required = false) Users users, Model model) {
        model.addAttribute("user", users);
        model.addAttribute("bookList", bookService.getBookList());
        return "/admin/book";
    }

    @GetMapping("/addBook")
    public String addBook(@SessionAttribute(value = "user", required = false) Users users, Model model) {
        model.addAttribute("user", users);
        return "/admin/add-book";
    }

    @GetMapping("/person")
    public String person(@SessionAttribute(value = "user", required = false) Users users, Model model) {
        model.addAttribute("user", users);
        return "/admin/person";
    }
}
